package com.common.frame.utils;

import androidx.recyclerview.widget.DiffUtil;

import com.common.frame.bean.DiffBean;

import java.util.List;


/**
 * create by sunxy on 2020/11/27
 **/
public class SunDiffCallBack extends DiffUtil.Callback {

    private List<DiffBean> oldData;
    private List<DiffBean> newData;

    public SunDiffCallBack() { }

    public SunDiffCallBack(List<DiffBean> oldData, List<DiffBean> newData) {
        this.oldData = oldData;
        this.newData = newData;
    }

    public SunDiffCallBack resetData(List<DiffBean> oldData, List<DiffBean> newData) {
        this.oldData = oldData;
        this.newData = newData;
        return this;
    }

    @Override
    public int getOldListSize() {
        return oldData == null ? 0 : oldData.size();
    }

    @Override
    public int getNewListSize() {
        return newData == null ? 0 : newData.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return oldData.get(oldItemPosition).toString().equals(newData.get(newItemPosition).toString());
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        return oldData.get(oldItemPosition).toString().equals(newData.get(newItemPosition).toString());
    }
}
